//
//  ThemeButton.m
//  ThemeChange
//
//  Created by 花花 on 2016/12/8.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "ThemeButton.h"

@implementation ThemeButton


- (instancetype)init{

    return [self initWithFrame:CGRectZero];
}

- (instancetype)initWithFrame:(CGRect)frame{


    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

-(void)awakeFromNib{

    [super awakeFromNib];
    [self setup];
}


-(void)setup{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(themeDidChange) name:kThemeDidChangeNotification object:nil];

}
-(void)themeDidChange{

    UIImage *img =[[ThemeManager shareManager]loadImageWithImgName:_imageName];
    UIImage *hightImg =[[ThemeManager shareManager]loadImageWithImgName:_highLightImageName];
    UIImage *backImg = [[ThemeManager shareManager]loadImageWithImgName:_backImageName];
    UIImage *backHighImg =[[ThemeManager shareManager]loadImageWithImgName:_backHighLightImageName];
    
    [self setImage:img forState:UIControlStateNormal];
    [self setImage:hightImg forState:UIControlStateHighlighted];
    [self setBackgroundImage:backImg forState:UIControlStateNormal];
     [self setImage:backHighImg forState:UIControlStateHighlighted];
}

-(void)dealloc{

    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

-(void)setImageName:(NSString *)imageName{

    if (_imageName != imageName) {
        _imageName =[imageName copy];
    
        [self themeDidChange];
    }

    
}
-(void)setHighLightImageName:(NSString *)highLightImageName{


    if (_highLightImageName != highLightImageName) {
        _highLightImageName =[highLightImageName copy];
        [self themeDidChange];
    }

}

-(void)setBackImageName:(NSString *)backImageName{

    if (_backImageName != backImageName) {
        _backImageName =[backImageName copy];
        
        [self themeDidChange];
    }

}
-(void)setBackHighLightImageName:(NSString *)backHighLightImageName{

    if (_backHighLightImageName != backHighLightImageName) {
        _backHighLightImageName =[backHighLightImageName copy];
        
        [self themeDidChange];
    }

}


@end
